#!/bin/bash

# 创建项目根目录
mkdir -p deepseek4j-demo
cd deepseek4j-demo

# 创建模块目录结构
for module in common api web; do
    mkdir -p deepseek4j-${module}/src/main/java/com/example/${module}
    mkdir -p deepseek4j-${module}/src/main/resources
    mkdir -p deepseek4j-${module}/src/test/java
    mkdir -p deepseek4j-${module}/src/test/resources
done

# 创建 common 模块的类目录
mkdir -p deepseek4j-common/src/main/java/com/example/common/model

# 创建 web 模块的控制器目录
mkdir -p deepseek4j-web/src/main/java/com/example/web/controller

# 创建所有需要的文件
# 1. 父 pom.xml
cat > pom.xml << 'EOL'
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.18</version>
    </parent>

    <groupId>com.example</groupId>
    <artifactId>deepseek4j-demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>deepseek4j-common</module>
        <module>deepseek4j-api</module>
        <module>deepseek4j-web</module>
    </modules>

    <properties>
        <java.version>11</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>2.7.18</spring-boot.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.example</groupId>
                <artifactId>deepseek4j-common</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.example</groupId>
                <artifactId>deepseek4j-api</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.example</groupId>
                <artifactId>deepseek4j-web</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.30</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
EOL

# 2. common 模块 pom.xml
cat > deepseek4j-common/pom.xml << 'EOL'
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>deepseek4j-demo</artifactId>
        <groupId>com.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>deepseek4j-common</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>
EOL

# 3. api 模块 pom.xml
cat > deepseek4j-api/pom.xml << 'EOL'
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>deepseek4j-demo</artifactId>
        <groupId>com.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>deepseek4j-api</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>deepseek4j-common</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>
EOL

# 4. web 模块 pom.xml
cat > deepseek4j-web/pom.xml << 'EOL'
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>deepseek4j-demo</artifactId>
        <groupId>com.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>deepseek4j-web</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>deepseek4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
EOL

# 5. 创建 Java 类文件
# ChatRequest.java
cat > deepseek4j-common/src/main/java/com/example/common/model/ChatRequest.java << 'EOL'
package com.example.common.model;

import lombok.Data;

@Data
public class ChatRequest {
    private String message;
    private String provider; // "tencent" or "alibaba"
}
EOL

# ChatResponse.java
cat > deepseek4j-common/src/main/java/com/example/common/model/ChatResponse.java << 'EOL'
package com.example.common.model;

import lombok.Data;

@Data
public class ChatResponse {
    private String message;
    private String provider;
    private Long timestamp;
}
EOL

# DeepseekService.java
mkdir -p deepseek4j-api/src/main/java/com/example/api/service
cat > deepseek4j-api/src/main/java/com/example/api/service/DeepseekService.java << 'EOL'
package com.example.api.service;

import com.example.common.model.ChatRequest;
import com.example.common.model.ChatResponse;

public interface DeepseekService {
    ChatResponse chat(ChatRequest request);
}
EOL

# DeepseekApplication.java
mkdir -p deepseek4j-web/src/main/java/com/example/web
cat > deepseek4j-web/src/main/java/com/example/web/DeepseekApplication.java << 'EOL'
package com.example.web;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = "com.example")
public class DeepseekApplication {
    public static void main(String[] args) {
        SpringApplication.run(DeepseekApplication.class, args);
    }
}
EOL

# ChatController.java
cat > deepseek4j-web/src/main/java/com/example/web/controller/ChatController.java << 'EOL'
package com.example.web.controller;

import com.example.api.service.DeepseekService;
import com.example.common.model.ChatRequest;
import com.example.common.model.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/chat")
public class ChatController {

    @Autowired
    private DeepseekService deepseekService;

    @PostMapping
    public ChatResponse chat(@RequestBody ChatRequest request) {
        return deepseekService.chat(request);
    }
}
EOL

# 6. 创建配置文件
cat > deepseek4j-web/src/main/resources/application.yml << 'EOL'
server:
  port: 8080

spring:
  application:
    name: deepseek4j-demo
EOL

# 设置执行权限
#chmod +x create-project.sh

echo "项目创建完成！"
EOL